#ifndef __SENTENCE_H
#define __SENTENCE_H

#include "util.h"

struct Sentence;

struct SegmentFragment
{
	wchar_t* begin;
	wchar_t*  end;

	SegmentFragment * next;
	SegmentFragment * previous;

	~SegmentFragment()
	{
		
	}
	SegmentFragment()
	{
		begin = 0;
		end = 0;
		previous = next = 0;
	}
	SegmentFragment(wchar_t* b, wchar_t* e)
	{
		begin = b;
		end = e;

		previous = next = 0;
	}

	SegmentFragment& operator++()
	{
		return *next;
	}
	SegmentFragment& operator++(int)
	{
		return *next;
	}

	SegmentFragment& operator--()
	{
		return *previous;
	}
	SegmentFragment& operator--(int)
	{
		return *previous;
	}

	friend bool operator==(const SegmentFragment& lsf, const SegmentFragment& rsf);
	friend bool operator!=(const SegmentFragment& lsf, const SegmentFragment& rsf);
	friend bool operator<(const SegmentFragment& lsf, const SegmentFragment& rsf);
	friend bool operator>(const SegmentFragment& lsf, const SegmentFragment& rsf);
};


struct Sentence
{
	wchar_t * se;
	
	bool needSeg;
	int length; // length excluding begin and ending.
	
	SegmentFragment *head;
	
	Sentence *next;

	Sentence()
	{
		se = 0;
		needSeg=false;
		length = 0;
		
		head = 0;
	}

	~Sentence()
	{
		SegmentFragment * nextSeg=head;
		while(head != 0)
		{
			nextSeg = head->next;
			delete head;
			head = nextSeg;
		}
		delete se;
	}
	
	void addSegmentFragment(wchar_t * begin, wchar_t * end)
	{
		SegmentFragment* node = new SegmentFragment(begin,end);
		if(head == 0)
		{
			head = node;
			head->next = 0;
			head->previous = 0;

		}else{
			node->previous = 0;
			node->next = head;
			
			head->previous = node;
			head = node;
		}
		
	}

	void printResult()
	{
		if(this->needSeg)
		{
			SegmentFragment * cur=head;
			while( (cur) != 0)
			{
				print_wchar(cur->begin,cur->end-cur->begin +1 );
				printf("/ ");
				cur = cur->next;
			}
		}
		else
		{
			print_wchar(se);
		}
	}
};

#endif